import com.fz.entity.Student;
import com.fz.entity.Teacher;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Z-C-Y on 2018-02-02.
 *      构造方法的注入形式aa()
 *      属性的注入bb()
 */
public class Demo {

   @Test
    public void bb(){
       /*测试属性注入*/
       BeanFactory fb = new ClassPathXmlApplicationContext("applicationContext.xml");
       Teacher  t1 = fb.getBean("t1",Teacher.class);
       Teacher  t2 = fb.getBean("t2",Teacher.class);
       System.out.println("==t1=="+t1.getName()+"年龄："+t1.getAge());
       System.out.println("==t2=="+t2.getName()+"年龄："+t2.getAge());
        System.out.println(t1);
        System.out.println(t2);
    }







    @Test
    public void aa(){
        BeanFactory f = new ClassPathXmlApplicationContext("applicationContext.xml");
       // Student s = f.getBean(Student.class);
      //  System.out.println(s);
      //  Teacher t  = f.getBean(Teacher.class);
       // System.out.println(t.getName());
     //   Student st = f.getBean("st",Student.class);
      //  Student ss = f.getBean("ss",Student.class);
        //System.out.println(st.getTeacher().getName());
      //  System.out.println(ss.getTeacher().getName());

       Student s3 = f.getBean("s3",Student.class);
       Student s4 = f.getBean("s4",Student.class);
       Student s5= f.getBean("s5",Student.class);

        System.out.println("==s3==="+s3);
        System.out.println("==s4==="+s4);
        System.out.println("==s5==="+s5);

        /*时间的处理*/
        SimpleDateFormat s1 = f.getBean("sdf1",SimpleDateFormat.class);
        SimpleDateFormat s2 = f.getBean("sdf2",SimpleDateFormat.class);
        Date d = f.getBean("date",Date.class);
        System.out.println("====s1==="+s1.format(d));
        System.out.println("===s2===="+s2.format(d));

    }


}
